<html>
	<head>
	
		<style>
		body {
			min-width:200px;
			overflow-x:hidden;
		}
		</style>
		
		<script>	
		function exportData()
		{
			getRawData();
		}
		
		function getRawData()
		{
			chrome.tabs.getSelected(
				null, 
				function(tab) {
					chrome.tabs.sendRequest(
						tab.id, 
						{action: "getDOM"}, 
						function(response) {
							extractData(response.dom);
						}
					);
				}
			);
		}
		
		// extracts the data selected by the user
		// via the select_data dropdown
		function extractData(rawData)
		{
			// all = all data on page, basically what version 0.1 did
			// raw = all data but without labels - POTENTIAL
			// ds = daily summaries only - POTENTIAL
			// os = one overall summary - POTENTIAL
			var whichData = document.getElementById("select_data").value;
			
			var dataBegins = rawData.indexOf("Exercise notes") + 14;
			rawData = rawData.substring(dataBegins);
			
			if(whichData == "all")
			{
				rawData = extractAllData(rawData);
			}
			else if(whichData == "raw")
			{
				rawData = extractRawData(rawData);
			}
			else if(whichData == "ds")
			{
				rawData = extractDailySummaries(rawData);
			}
			else if(whichData == "os")
			{
				rawData = extractOverallSummary(rawData);
			}
			
			// ready to set the format
			setFormat(rawData);
		}
		
		// sets the format of the data selected by 
		// the user via the select_format dropdown
		function setFormat(rawData)
		{
			// tab = tab delimited
			// csv = comma separated - POTENTIAL
			// xml = xml - POTENTIAL
			var whichFormat = document.getElementById("select_format").value;
			
			if(whichFormat == "tab")
			{
			}
			
			// ready to download
			downloadifyData(rawData);
		}
			
		function downloadifyData(rawData)
		{
			var bb = new BlobBuilder(); 
			bb.append(rawData); 
			var url = createObjectURL(bb.getBlob()); 
			//window.open(url); 
			alert(saveAs);
		}
		
		// data extraction functions
		function extractAllData(rawData)
		{
			return rawData;
		}
		
		function extractRawData(rawData)
		{
			return rawData;
		}
		
		function extractDailySummaries(rawData)
		{
			return rawData;
		}
		
		function extractOverallSummary(rawData)
		{
			return rawData;
		}
		
		</script>
		
	</head>
	
	<body>
		<table border="0">
		<tr><td>
		<label for="select_data">Select Data</label>
		</td></tr>
		<tr><td>
		<select id="select_data">
			<option value="all"> All Data </option>
		</select>
		</td></tr>
		
		<tr><td>
		<label for="select_format">Select Format</label>
		</td></tr>
		<tr><td>
		<select id="select_format">
			<option value="tab"> Tab Delimited </option>
		</select>
		</td></tr>
		
		<tr><td>
		<input type="button" value="Export Data" onclick="exportData()">
		</td></tr>
		</table>
	</body>

</html>